//
//  PayFoodMaterialTableViewCell.m
//  Menu
//
//  Created by dllo on 15/7/7.
//  Copyright (c) 2015年 lijiangang. All rights reserved.
//

#import "PayFoodMaterialTableViewCell.h"

@implementation PayFoodMaterialTableViewCell

- (void)dealloc
{
    [_materialLabel release];
    [_materialImgView release];
    [super dealloc];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self createSubViews];
    }
    return self;
}

-(void)createSubViews
{
    self.materialLabel = [[UILabel alloc] initWithFrame:CGRectMake(25*WIDTH, 10*HEIGHT, 325*WIDTH, 50*HEIGHT)];
    self.materialLabel.backgroundColor = [UIColor whiteColor];
    self.materialLabel.numberOfLines = 0;
    self.materialLabel.font = [UIFont systemFontOfSize:17];
    [self.contentView addSubview:self.materialLabel];
    [_materialLabel release];

    self.materialImgView = [[UIImageView alloc] initWithFrame:CGRectMake(25*WIDTH, self.materialLabel.frame.origin.y + self.materialLabel.frame.size.height +10*HEIGHT, self.materialLabel.frame.size.width, 200*HEIGHT)];

    self.materialImgView.layer.borderColor = [UIColor lightGrayColor].CGColor;
    self.materialImgView.layer.borderWidth = 1;
    [self.contentView addSubview:self.materialImgView];
    [_materialImgView release];
}

-(void)setPayFoodModel:(PayFoodModel *)payFoodModel
{
    if (_payFoodModel != payFoodModel)
    {
        [_payFoodModel release];
        _payFoodModel = [payFoodModel retain];
    }
    self.materialLabel.text = payFoodModel.materialPrepare;
    [self.materialImgView sd_setImageWithURL:[NSURL URLWithString:payFoodModel.materialImage]];
    CGFloat LabelHeight = [[self class] heightForLabel:self.materialLabel.text Width:self.materialLabel.frame.size.width Height:1000*HEIGHT Font:17];
    CGRect LabelFrame = self.materialLabel.frame;
    LabelFrame.size.height = LabelHeight;
    self.materialLabel.frame = LabelFrame;
    self.materialImgView.frame = CGRectMake(self.materialLabel.frame.origin.x, self.materialLabel.frame.origin.y + self.materialLabel.frame.size.height + 10*HEIGHT, self.materialLabel.frame.size.width, 200*HEIGHT);
}

+(CGFloat)heightForLabel:(NSString *)text Width:(CGFloat)width Height:(CGFloat)height Font:(CGFloat)font
{
    CGSize size = CGSizeMake(width, height);
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithObject:[UIFont systemFontOfSize:font] forKey:NSFontAttributeName];
    CGRect frame = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return frame.size.height;
}























- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
